﻿@page "/"
@using Microsoft.EntityFrameworkCore
@using LuckyFish.Blog.Models
@using LuckyFish.Blog.Controls
@inject IDbContextFactory<BlogContext> DbFactory

<PageTitle>主页</PageTitle>

@if (Array.Length == 0)
{
    <Empty Image="https://gw.alipayobjects.com/zos/antfincdn/ZHrcdLPrvN/empty.svg" Width="133" Text="暂无文章"/>
}
else
{
    <Row ColSpan="4">
        @for (var i = 0; i < Array.Length; i++)
        {
            <ArticleControl Model="Array[i]" Mode="@(i % 2 == 0 ? "" : "Left")"/>
        }
    </Row>
}


@code
{
    private ArticleModel[] Array { get; set; } = System.Array.Empty<ArticleModel>();

    protected override async Task OnInitializedAsync()
    {
        await base.OnInitializedAsync();
        var context = await DbFactory.CreateDbContextAsync();
        Array = await context.Articles
            .Include(x => x.Labels).ToArrayAsync();
    }
}